//新添加子页面的div名字
var divm = "";	  
//触发新页面动作
var index_subhtml = "";
//新页面随机码
var random_subhtml = "";
//回调函数
var call_vue_funcName = "";
//页面按钮禁用权限
var T00000_N01_GHT003 = null;

(function($) {
	$.each(['show','hide'], function(i, val) {
        var _org = $.fn[val];
        $.fn[val] = function() {
            this.trigger(val);
            return _org.apply(this, arguments);
        };
    });
})(jQuery);

var iS = 60;
//定时器
setInterval(function(){
	$("#N0001_SetTime").html("倒计时发送指令:<font color='red'>"+iS.toString()+"</font>");
	$("#N0002_SetTime").html("站点联网刷新倒计时指令:<font color='red'>"+iS.toString()+"</font>");
	$("#N0003_SetTime").html("仪器状态刷新倒计时指令:<font color='red'>"+iS.toString()+"</font>");
	$("#N0004_SetTime").html("设备工况刷新倒计时指令:<font color='red'>"+iS.toString()+"</font>");
	iS = iS - 1;
	if(iS < 0)
		iS = 60;
},1000);

/**************websocket定义开始****************/
var wSck = null;
if(contextPath == "")
	wSck = new WebSocket("ws://"+host+"/websockets")
else
	wSck = new WebSocket("ws://"+host+"/"+contextPath+"/websockets")
	
wSck.onopen = function (evt) {
    if (wSck.readyState === 1) {
    	wSck.send('##001##');
    }
    //console.log("opened "+evt.toString());
};

wSck.onclose = function (evt) {
    //console.log("closed "+evt.toString());
};

wSck.onmessage = function (evt) {
	//layer.close(ly_index);
	//接收到的后台程序数据，json格式
//	if(evt.data.toString() == "发送websocket数据到页面==>")
//		alert(evt.data.toString());
    var jso = JSON.parse(evt.data);
    if(jso.hasOwnProperty("N01_NG40J5") && jso["N01_NG40J5"].length > 0){
    	var temHtml = s_decode(jso["N01_NG40J5"][0]["URL_PATH"]);
    	var temRandom = s_decode(jso["N01_NG40J5"][0]["URL_RANDOM"]);
    	//调用或加载左侧菜单并click
    	Add_No_Show_Menu(temHtml,temRandom,JSON.parse("{}"));
    	//弹窗页面
//    	T00000_open_win(temHtml,temRandom);
    }
    if(jso.hasOwnProperty("N01_CMDDOW") && jso["N01_CMDDOW"].length > 0){
    	var temCMD_NAME = s_decode(jso["N01_CMDDOW"][0]["CMD_NAME"]);
    	var temDEVICE_NAME = s_decode(jso["N01_CMDDOW"][0]["DEVICE_NAME"]);
    	var temGET_TIME = s_decode(jso["N01_CMDDOW"][0]["GET_TIME"]);
    	
    	$("#N0001_Show").html("<font color='red'>人工发送指令操作成功:"+temCMD_NAME+"=>"+temDEVICE_NAME+"指令时间=>"+temGET_TIME+"</font>");
    	iS = 3600;
//	    swal("人工发送指令操作成功!",temDEVICE_NAME+",发送指令:"+temCMD_NAME, "success");
    }
    if(jso.hasOwnProperty("N01_CMD_INTERVAL") && jso["N01_CMD_INTERVAL"].length > 0){
    	var temCMD_NAME = s_decode(jso["N01_CMD_INTERVAL"][0]["CMD_NAME"]);
    	var temDEVICE_NAME = s_decode(jso["N01_CMD_INTERVAL"][0]["DEVICE_NAME"]);
    	var temGET_TIME = s_decode(jso["N01_CMD_INTERVAL"][0]["GET_TIME"]);
    	$("#N0001_Show").html("<font color='red'>定时器自动发送指令操作成功:"+temCMD_NAME+"=>"+temDEVICE_NAME+"=>指令时间=>"+temGET_TIME+"</font>");
    	iS = 3600;
//	    swal("定时器自动发送指令操作成功!",temDEVICE_NAME+",发送指令:"+temCMD_NAME, "success");
    }
    if(jso.hasOwnProperty("STATION_STATE")){
    	$("#N0002_STATION_COUNT").html(jso["STATION_STATE"].length.toString());
    	$("#N0002_STATION_STATE").html("");
    	$.each(jso["STATION_STATE"], function (jindex, obj2) {
    		var ONLINE_STATE = "";
    		if(obj2["ONLINE_STATE"] == "1")
    			ONLINE_STATE = s_decode(obj2["STATION_NAME"])+"("+s_decode(obj2["STATION_IP"])+")"+"<font color='blue'>在线</font>";
    		else
    			ONLINE_STATE = s_decode(obj2["STATION_NAME"])+"("+s_decode(obj2["STATION_IP"])+")"+"<font color='red'>离线</font>";
    			
    		var div_s = "<div class=\"left\">"
	                  +"	<div class=\"author-name\">"
	                  +"		<small class=\"chat-date\">"
	                  +"		</small>"
	                  +"	</div>"
	                  +"	<div class=\"chat-message active\">"+ONLINE_STATE
	                  +"	</div>"
	                  +"</div>";
    		$("#N0002_STATION_STATE").append(div_s);
    	});
    }
    if(jso.hasOwnProperty("h_device_status_overview")){
    	var h_device_status_overview = jso["h_device_status_overview"];
    	var h_device_status_overview_station_code_count = {};
    	$.each(h_device_status_overview, function (jindex, obj2) {
			obj2["NETWORK_STATUS"] = "0";
			if(s_decode(obj2["GET_TIME"]) != "" &&  new Date(s_decode(obj2["GET_TIME"])) >= new Date(new Date().setMinutes(new Date().getMinutes()-3)).getTime()){
				obj2["NETWORK_STATUS"] = "1";
			}
    		var A661EC_station_code_div_array = $("#A661EC_h_device_status_overview_main").find(".A661EC_station_code");
    		var A661EC_DEVICE_CODE_HTML = "<span>"+s_decode(obj2["DEVICE_CODE"])+"</span>";
    		var A661EC_DEVICE_TYPE_HTML = "<span>"+s_decode(obj2["DEVICE_TYPE"])+"</span>";
    		var A661EC_DEVICE_NAME_HTML = "<span>"+s_decode(obj2["DEVICE_NAME"])+"</span>";
    		var A661EC_DEVICE_ADDRESS_HTML = "<span>"+s_decode(obj2["DEVICE_ADDRESS"])+"</span>";
    		var A661EC_NETWORK_CODE_HTML = "<span>"+s_decode(obj2["NETWORK_CODE"])+"</span>";
    		var A661EC_CURRENT_STATUS_HTML = "<span>"+s_decode(obj2["CURRENT_STATUS"])+"</span>";
			var A661EC_CURRENT_TASK_HTML = "<span>"+s_decode(obj2["CURRENT_TASK"])+"</span>";
			var A661EC_NETWORK_STATUS_HTML = "<span>"+s_decode(obj2["NETWORK_STATUS"])+"</span>";
			var A661EC_GET_TIME_HTML = "<span>"+s_decode(obj2["GET_TIME"])+"</span>";
			if(s_decode(obj2["NETWORK_STATUS"]) != "1"){
				A661EC_CURRENT_STATUS_HTML = "<span style=\"color:red;\">未知</span>";
			}
			else{
				if(s_decode(obj2["CURRENT_STATUS"]) == ""){
					A661EC_CURRENT_STATUS_HTML = "<span style=\"color:red;\">未知</span>";
				}
				else if(s_decode(obj2["CURRENT_STATUS"]) == "0"){
					A661EC_CURRENT_STATUS_HTML = "<span style=\"color:green;\">待机</span>";
				}
				else if(s_decode(obj2["CURRENT_STATUS"]) == "1"){
					A661EC_CURRENT_STATUS_HTML = "<span style=\"color:orange;\">测在线</span>";
				}
				else if(s_decode(obj2["CURRENT_STATUS"]) == "2"){
					A661EC_CURRENT_STATUS_HTML = "<span style=\"color:orange;\">标定</span>";
				}
				else if(s_decode(obj2["CURRENT_STATUS"]) == "3"){
					A661EC_CURRENT_STATUS_HTML = "<span style=\"color:orange;\">停机</span>";
				}
				else if(s_decode(obj2["CURRENT_STATUS"]) == "4"){
					A661EC_CURRENT_STATUS_HTML = "<span style=\"color:orange;\">维护</span>";
				}
				else if(s_decode(obj2["CURRENT_STATUS"]) == "5"){
					A661EC_CURRENT_STATUS_HTML = "<span style=\"color:orange;\">测实样</span>";
				}
				else if(s_decode(obj2["CURRENT_STATUS"]) == "6"){
					A661EC_CURRENT_STATUS_HTML = "<span style=\"color:orange;\">测质控</span>";
				}
				else if(s_decode(obj2["CURRENT_STATUS"]) == "7"){
					A661EC_CURRENT_STATUS_HTML = "<span style=\"color:orange;\">测标液</span>";
				}
				else if(s_decode(obj2["CURRENT_STATUS"]) == "8"){
					A661EC_CURRENT_STATUS_HTML = "<span style=\"color:orange;\">测离线</span>";
				}
			}
			if(s_decode(obj2["CURRENT_TASK"]) == ""){
				A661EC_CURRENT_TASK_HTML = "<span style=\"color:red;\">未知/无任务</span>";
			}
			else if(s_decode(obj2["CURRENT_TASK"]) == "1"){
				A661EC_CURRENT_TASK_HTML = "<span style=\"color:orange;\">量程校准</span>";
			}
			else if(s_decode(obj2["CURRENT_TASK"]) == "2"){
				A661EC_CURRENT_TASK_HTML = "<span style=\"color:orange;\">启动做样</span>";
			}
			else if(s_decode(obj2["CURRENT_TASK"]) == "3"){
				A661EC_CURRENT_TASK_HTML = "<span style=\"color:orange;\">重复性</span>";
			}
			else if(s_decode(obj2["CURRENT_TASK"]) == "4"){
				A661EC_CURRENT_TASK_HTML = "<span style=\"color:orange;\">示值误差</span>";
			}
			else if(s_decode(obj2["CURRENT_TASK"]) == "5"){
				A661EC_CURRENT_TASK_HTML = "<span style=\"color:orange;\">24H低浓度漂移</span>";
			}
			else if(s_decode(obj2["CURRENT_TASK"]) == "6"){
				A661EC_CURRENT_TASK_HTML = "<span style=\"color:orange;\">24H高浓度量程</span>";
			}
			else if(s_decode(obj2["CURRENT_TASK"]) == "7"){
				A661EC_CURRENT_TASK_HTML = "<span style=\"color:orange;\">定量下限</span>";
			}
			else if(s_decode(obj2["CURRENT_TASK"]) == "8"){
				A661EC_CURRENT_TASK_HTML = "<span style=\"color:orange;\">精密度</span>";
			}
			else if(s_decode(obj2["CURRENT_TASK"]) == "9"){
				A661EC_CURRENT_TASK_HTML = "<span style=\"color:orange;\">零点漂移</span>";
			}
			else if(s_decode(obj2["CURRENT_TASK"]) == "10"){
				A661EC_CURRENT_TASK_HTML = "<span style=\"color:orange;\">量程漂移</span>";
			}
			else if(s_decode(obj2["CURRENT_TASK"]) == "11"){
				A661EC_CURRENT_TASK_HTML = "<span style=\"color:orange;\">直线性</span>";
			}
			else if(s_decode(obj2["CURRENT_TASK"]) == "12"){
				A661EC_CURRENT_TASK_HTML = "<span style=\"color:orange;\">量程漂移-零漂前</span>";
			}
			else if(s_decode(obj2["CURRENT_TASK"]) == "13"){
				A661EC_CURRENT_TASK_HTML = "<span style=\"color:orange;\">量程漂移-零漂后</span>";
			}
			else if(s_decode(obj2["CURRENT_TASK"]) == "14"){
				A661EC_CURRENT_TASK_HTML = "<span style=\"color:orange;\">仪器标定</span>";
			}
			if(s_decode(obj2["NETWORK_STATUS"]) == ""){
				A661EC_NETWORK_STATUS_HTML = "<span style=\"color:red;\">未知</span>";
			}
			else if(s_decode(obj2["NETWORK_STATUS"]) == "0"){
				A661EC_NETWORK_STATUS_HTML = "<span style=\"color:red;\">断线</span>";
			}
			else if(s_decode(obj2["NETWORK_STATUS"]) == "1"){
				A661EC_NETWORK_STATUS_HTML = "<span style=\"color:green;\">在线</span>";
			}
    		var has_A661EC_station_code_div = 0;
    		for(let i=0;i<A661EC_station_code_div_array.length;i++){
    			if($($("#A661EC_h_device_status_overview_main").find(".A661EC_station_code")[i]).attr("value")==obj2["STATION_CODE"]){
    				has_A661EC_station_code_div = 1;
    			}
    		}
    		if(has_A661EC_station_code_div == 0){
    			var A661EC_station_code_div_html = "<div value=\""+obj2["STATION_CODE"]+"\" class=\"col-sm-12 A661EC_station_code\">"+
    												"<h3><strong>"+s_decode(obj2["STATION_NAME"])+"</strong></h3>"+
    												"</div>"
    			$("#A661EC_h_device_status_overview_main").append(A661EC_station_code_div_html);
    			h_device_status_overview_station_code_count[obj2["STATION_CODE"]] = 0;
    		}
    		A661EC_station_code_div_array = $("#A661EC_h_device_status_overview_main").find(".A661EC_station_code");
    		var A661EC_device_code_div_array = $("#A661EC_h_device_status_overview_main").find(".A661EC_device_code");
    		var has_A661EC_device_code_div = 0;
    		for(let i=0;i<A661EC_device_code_div_array.length;i++){
    			if($($("#A661EC_h_device_status_overview_main").find(".A661EC_device_code")[i]).attr("value")==obj2["DEVICE_CODE"]){
    				has_A661EC_device_code_div = 1;
    			}
    		}
    		if(has_A661EC_device_code_div == 0){
    			var A661EC_device_code_div_html= "<div value=\""+obj2["DEVICE_CODE"]+"\" class=\"col-sm-2 A661EC_device_code\">"+
		            "<div class=\"contact-box\">"+
	                  "<h3><strong>设备编号:</strong><strong id=\"DEVICE_CODE\">"+A661EC_DEVICE_CODE_HTML+"</strong></h3>"+
	                  "<h3><strong>设备类型:</strong><strong id=\"DEVICE_TYPE\">"+A661EC_DEVICE_TYPE_HTML+"</strong></h3>"+
	                  "<h3><strong>设备名称:</strong><strong id=\"DEVICE_NAME\">"+A661EC_DEVICE_NAME_HTML+"</strong></h3>"+
	                  "<h3><strong>设备地址:</strong><strong id=\"DEVICE_ADDRESS\">"+A661EC_DEVICE_ADDRESS_HTML+"</strong></h3>"+
	                  "<h3><strong>网络编号:</strong><strong id=\"NETWORK_CODE\">"+A661EC_NETWORK_CODE_HTML+"</strong></h3>"+
	                  "<h3><strong>当前状态:</strong><strong id=\"CURRENT_STATUS\" value=\""+obj2["CURRENT_STATUS"]+"\">"+A661EC_CURRENT_STATUS_HTML+"</strong></h3>"+
	                  "<h3><strong>当前任务:</strong><strong id=\"CURRENT_TASK\" value=\""+obj2["CURRENT_TASK"]+"\">"+A661EC_CURRENT_TASK_HTML+"</strong></h3>"+
	                  "<h3><strong>联网状态:</strong><strong id=\"NETWORK_STATUS\" value=\""+obj2["NETWORK_STATUS"]+"\">"+A661EC_NETWORK_STATUS_HTML+"</strong></h3>"+
	                  "<h3><strong>当前时间:</strong><strong id=\"GET_TIME\" value=\""+obj2["GET_TIME"]+"\">"+A661EC_GET_TIME_HTML+"</strong></h3>"+
	                  "<p style=\"text-align: center;\">"+
	                  "<button type=\"button\" class=\"btn btn-w-m btn-primary\" onclick=\"A661EC_detail('"+obj2["STATION_CODE"]+"','"+obj2["STATION_NAME"]+"','"+obj2["DEVICE_CODE"]+"','"+obj2["DEVICE_TYPE"]+"','"+obj2["DEVICE_NAME"]+"','"+obj2["DEVICE_ADDRESS"]+"','"+obj2["NETWORK_CODE"]+"')\">查看详情</button>"+
	                  "</p>"+
	                  "<p style=\"text-align: center;\">"+
	                  "<button type=\"button\" class=\"btn btn-w-m btn-primary\" onclick=\"A661EC_report()\">生成报告</button>"+
	                  "</p>"+
		            "</div>"+
		        "</div>";
    			for(let i=0;i<A661EC_station_code_div_array.length;i++){
        			if($($("#A661EC_h_device_status_overview_main").find(".A661EC_station_code")[i]).attr("value")==obj2["STATION_CODE"]){
        				if(h_device_status_overview_station_code_count[obj2["STATION_CODE"]] % 6 ==0){
        					$($("#A661EC_h_device_status_overview_main").find(".A661EC_station_code")[i]).append("<div class=\"row\"></div>");
        				}
        				$($($($("#A661EC_h_device_status_overview_main").find(".A661EC_station_code")[i])).find(".row")[Math.floor(h_device_status_overview_station_code_count[obj2["STATION_CODE"]]/6)]).append(A661EC_device_code_div_html);
        				h_device_status_overview_station_code_count[obj2["STATION_CODE"]] ++;
        			}
        		}
    		}
    		else{
    			for(let i=0;i<A661EC_station_code_div_array.length;i++){
        			if($($("#A661EC_h_device_status_overview_main").find(".A661EC_station_code")[i]).attr("value")==obj2["STATION_CODE"]){
        				var A661EC_sub_device_code_div_array = $($("#A661EC_h_device_status_overview_main").find(".A661EC_station_code")[i]).find(".A661EC_device_code");
        				for(let j=0;j<A661EC_sub_device_code_div_array.length;j++){
        	    			if($(A661EC_sub_device_code_div_array[j]).attr("value")==obj2["DEVICE_CODE"]){
        	    				$(A661EC_sub_device_code_div_array[j]).find("#CURRENT_STATUS").html(A661EC_CURRENT_STATUS_HTML);
                				$(A661EC_sub_device_code_div_array[j]).find("#CURRENT_TASK").html(A661EC_CURRENT_TASK_HTML);
                				$(A661EC_sub_device_code_div_array[j]).find("#NETWORK_STATUS").html(A661EC_NETWORK_STATUS_HTML);
                				$(A661EC_sub_device_code_div_array[j]).find("#GET_TIME").html(A661EC_GET_TIME_HTML);
                				$(A661EC_sub_device_code_div_array[j]).find("#CURRENT_STATUS").attr("value",obj2["CURRENT_STATUS"]);
                				$(A661EC_sub_device_code_div_array[j]).find("#CURRENT_TASK").attr("value",obj2["CURRENT_TASK"]);
                				$(A661EC_sub_device_code_div_array[j]).find("#NETWORK_STATUS").attr("value",obj2["NETWORK_STATUS"]);
                				$(A661EC_sub_device_code_div_array[j]).find("#GET_TIME").attr("value",obj2["#GET_TIME"]);
        	    			}
        	    		}
        			}
        		}
    		}

    		if($("#A661ED_h_device_detail").find("#A661ED_DEVICE_CODE").text()==obj2["DEVICE_CODE"] &&
    			$("#A661ED_h_device_detail").find("#A661ED_STATION_CODE").text()==obj2["STATION_CODE"]){
    			$("#A661ED_h_device_detail").find("#A661ED_CURRENT_STATUS").html(A661EC_CURRENT_STATUS_HTML);
    			$("#A661ED_h_device_detail").find("#A661ED_CURRENT_TASK").html(A661EC_CURRENT_TASK_HTML);
    			$("#A661ED_h_device_detail").find("#A661ED_NETWORK_STATUS").html(A661EC_NETWORK_STATUS_HTML);
    			$("#A661ED_h_device_detail").find("#A661ED_GET_TIME").html(A661EC_GET_TIME_HTML);    		}
    		if($("#AD9368_find_DEVICE_CODE").val()==obj2["DEVICE_CODE"] &&
    				$("#AD9368_find_STATION_CODE").val()==obj2["STATION_CODE"]){
    			var AD9368_device_status_div_list = $("[id^='AD9368_device_status_div_']");
    			for(let k=0;k<AD9368_device_status_div_list.length;k++){
    				var kk = k;
    				if (k<10){
    					kk = "0"+k;
    				}
    				else{
    					kk = k;
    				}
        			if(obj2["htCoilStatus_VAL_"+kk] == "1"){
        				if(k != 1){
        					$(AD9368_device_status_div_list[k]).css("background-color","rgba(0,255,0,1)");
        				}
        				else{
        					$(AD9368_device_status_div_list[k]).css("background-color","rgba(255,0,0,1)");
        				}
        			}
        			else{
        				if(k != 1){
        					$(AD9368_device_status_div_list[k]).css("background-color","rgba(255,0,0,1)");
        				}
        				else{
        					$(AD9368_device_status_div_list[k]).css("background-color","rgba(0,255,0,1)");
        				}
        			}
    			}
    		}
    	});
    	//console.log(h_device_status_overview);
    }
    else{
	    var Msg = evt.data;
//	    swal("收到操作成功!",Msg, "success");
    }
};

wSck.onerror = function(evt){
//    console.log("error "+evt.toString());
}
/**************websocket定义结束****************/
//打开弹窗页面
function T00000_open_win(temindex_subhtml,teminput_random){
	index_subhtml = s_decode(temindex_subhtml);
	random_subhtml = s_decode(teminput_random);
	//本页面传到其他页面参数
	if(loadHtmlSubVueFun(index_subhtml,"index_call_vue_layer") == true){
		var n = Get_RandomDiv(random_subhtml,"");
		layer.open({
			type: 1,
			area: ['1100px', '600px'],
			fixed: false, //不固定
			maxmin: true,
			content: $(n),
			success: function(layero, index){
				var T00000_toparam = {};
				T00000_toparam["ly_index"] = index;
				eval(random_subhtml+"_param = {}");
				for(var key in T00000_toparam)
					eval(inputrandom+"_param['"+key+"'] = '"+T00000_toparam[key]+"'");
				//参数传递并赋值
				eval(random_subhtml+"_param_set()");
				var tbName = "";
				if(index_subhtml.indexOf("/") == -1)
					tbName = index_subhtml.substring(0,index_subhtml.indexOf(".vue"));
				else
					tbName = index_subhtml.substring(index_subhtml.lastIndexOf("/")+1,index_subhtml.indexOf(".vue"));
				eval(random_subhtml+"_init_"+tbName+"()");
			},
			end: function(){
				$(n).hide();
			}
		});	
	}
}

//弹窗vue回调
function index_call_vue_layer(objResult){
	var index_suburl = index_subhtml.substring(0,index_subhtml.lastIndexOf(".vue"));
	var index_subname = index_suburl.substring(index_subhtml.lastIndexOf("/")+1,index_suburl.length);
	var n = Get_RandomDiv(random_subhtml,objResult);	
	layer.open({
		type: 1,
        area: ['1100px', '600px'],
        fixed: false, //不固定
        maxmin: true,
        content: $(n),
        success: function(layero, index){
        	var T00000_toparam = {};
        	T00000_toparam["ly_index"] = index;	
        	loadScript_hasparam(index_suburl+".js",random_subhtml+"_"+index_subname+"_biz_start",T00000_toparam);
    		//全局变量传递页面参数重置
    		Temp_toparam = {};
        },
		end: function(){
			$(n).hide();
		}
    });
}

//空函数
function T00000_init_biz_start(input){
}

//仅获取子页div不创建
function Get_RDivNoBuild(temRandom,objResult){
	var divIndex = "";
	$.each($(".J_menuItem"), function (i, obj) {
		if($(obj).attr("attrandom") == temRandom){
			divIndex = temRandom +"_div"+$(obj).attr("data-index");
		}
	});
	if(divIndex == "")
		divIndex = temRandom +"_div";
	return "#"+divIndex;
}

//获取子页div，没有则创建并返回
function Get_RandomDiv(temRandom,objResult){
	if($("#"+temRandom +"_div999").length > 0)
		return "#"+temRandom +"_div999";
	
	var divIndex = "";
	$.each($(".J_menuItem"), function (i, obj) {
		if($(obj).attr("attrandom") == temRandom){
			divIndex = temRandom +"_div"+$(obj).attr("data-index");
		}
	});
	if(divIndex == "")
		divIndex = temRandom +"_div";
	if($("#"+divIndex).length > 0)
	{
		if($("#"+divIndex).html() == "" && objResult != "")
			$("#"+divIndex).append(objResult);
		return "#"+divIndex;
	}
	else
	{
		var nn = "<div id='" + divIndex + "' name='" + divIndex + "' data-id=''></div>";
		$(".J_mainContent").append(nn);
		$("#"+divIndex).append(objResult);
		return "#"+divIndex;
	}
}

//业务逻辑数据开始
function biz_start() {
	layer.close(ly_index);
    /*biz begin*/
	
	index_biz_start();	
    /*biz end*/
}

function index_biz_start(){
	//接口调试
	$("#upd_pwd").click(function(){
		index_subhtml = "upd_pwd.vue";
		if(loadHtmlSubVue(index_subhtml) == true){
			B44HT5_clear_input();
			layer.open({
				type:1,
				area: ['600px', '350px'],
				fixed: false, //不固定
				maxmin: true,
				content: $("#B44HT5_div"),
				success: function(layero, index){
					B44HT5_ly_index = index;
				},
				end: function(){
				}
			});
		}
	});
	$("#user_info").html("<i class='fa fa-user'></i>欢迎您："+nick_name);
	//菜单加载
	set_menu_info();
}

//获取菜单及相关信息
function set_menu_info(){
	layer.close(ly_index);
    /*biz begin*/

    var inputdata = {
        "param_name": "APP_USER_ZXY",
        "session_id": session_id,
        "login_id": login_id,
//        "param_value1":"16D0D0BD01343BD0AD6781ED5C671C8D" 旧权限模式
        "param_value1":"CD7A2038F1348BE881BD593174E90FBC" //新权限模式
        ,"param_value2":user_main_id
    };
    ly_index = layer.load();
    get_ajax_baseurl(inputdata, "get_APP_USER_ZXY");	
}

//设置菜单及相关信息,新权限模式
function get_APP_USER_ZXY(input){
	layer.close(ly_index);
	//查询失败
	if (Call_QryResult(input.APP_USER_ZXY) == false)
		return false;
	var auz = input.APP_USER_ZXY;
	var menu_info = input["N01_GHT001"];
	//首页菜单
	var menu_content = input["N01_GHT002"];
	//禁用按钮权限
	T00000_N01_GHT003 = input["N01_GHT003"];
	
	var temGROUP_ID = "";
	$.each(menu_info, function (i, obj) {
		if(temGROUP_ID != obj[GetLowUpp("GROUP_ID")]){
			//class=\"active\" 展开
			var divGroup = "<li  id=\""+obj[GetLowUpp("GROUP_EN_NAME")]+"\">"
					 +"		<a href=\"#\">"
					 +"			<i class=\""+s_decode(obj[GetLowUpp("GROUP_ICON")])+"\"></i>"
					 +"			<span class=\"nav-label\">"+s_decode(obj[GetLowUpp("GROUP_CN_NAME")])+"</span>"
					 +"			<span class=\"fa arrow\"></span>"
					 +"		</a>"
					 +"		<ul class=\"nav nav-second-level\" id =\""+obj[GetLowUpp("GROUP_EN_NAME")]+"_menu\">"
					 +"		</ul>"
					 +"</li>"
			$("#side-menu").append(divGroup);
			temGROUP_ID = obj[GetLowUpp("GROUP_ID")];
		}
		
		var objInfo = obj;
		if(temGROUP_ID == obj[GetLowUpp("GROUP_ID")].toString()){
			//首页不加载
			if(menu_content.length > 0 && menu_content[0][GetLowUpp("S_DESC")] == obj[GetLowUpp("S_DESC")]){
				
			}
			else if(s_decode(objInfo[GetLowUpp("MENU_URL")]).lastIndexOf(".vue") != -1 && s_decode(objInfo[GetLowUpp("MENU_URL")]).lastIndexOf(".vue") == s_decode(objInfo[GetLowUpp("MENU_URL")]).length - 4)
			{	var divMenuInfo = "<li>"
								+ "<a class=\"J_menuItem\" href=\""+s_decode(objInfo[GetLowUpp("MENU_URL")])+"\" attRandom=\""+objInfo[GetLowUpp("S_DESC")]+"\">"+s_decode(objInfo[GetLowUpp("MENU_NAME")])+"</a>"
								+ "</li>";
				$("#"+obj[GetLowUpp("GROUP_EN_NAME")]+"_menu").append(divMenuInfo);
			}
			else
			{
				var divMenuInfo = "<li>"
								+ "<a class=\"J_menuItem\" href=\""+s_decode(objInfo[GetLowUpp("MENU_URL")])+"\" attRandom=\""+objInfo[GetLowUpp("S_DESC")]+"\">"+s_decode(objInfo[GetLowUpp("MENU_NAME")])+"</a>"
								+ "</li>";
				$("#"+obj[GetLowUpp("GROUP_EN_NAME")]+"_menu").append(divMenuInfo);	
			}
		}
		
	});
	var bFlag = false;
	var menu_cont_Random = "T00000";
	if(menu_content.length > 0){
//	$.each(menu_content, function (j, objInfo) {
//	});
		objInfo = menu_content[0];
		menu_cont_Random = objInfo[GetLowUpp("S_DESC")];
		var temUrl = s_decode(objInfo[GetLowUpp("MENU_URL")]);
		var iR = IsVueOrHml(temUrl);
		if(iR == 2){
			$("#main_menu").attr("data-id",temUrl);
			$("#iframe0").attr("src",temUrl);
			$("#iframe0").attr("data-id",temUrl);
			$("#iframe0").show();
		}
		else if(iR == 1){
			$("#main_menu").attr("data-id",temUrl);
			$("#main_menu").attr("attrandom",menu_cont_Random);
			$("#iframe0").hide();
			var nn = "<div id='"+menu_cont_Random+"_div999' name='"+menu_cont_Random+"_div999'></div>";
			$(".J_mainContent").append(nn);
			index_subhtml = temUrl;
			divm = menu_cont_Random+"_div999";
			random_subhtml = menu_cont_Random+"_";
			call_vue_funcName = "";
			$("#"+menu_cont_Random+"_div999").attr("data-id",temUrl);
			loadScript_nofun(temUrl+"?callback=ReadCommonRes");
		}
	}
	else if(menu_content.length == 0)
	{
		$("#iframe0").hide();
		$("#main_menu").attr("data-id","init.vue");
		$("#main_menu").attr("attrandom",menu_cont_Random);
		var nn = "<div id='"+menu_cont_Random+"_div999' name='"+menu_cont_Random+"_div999'></div>";
		$(".J_mainContent").append(nn);
		index_subhtml = "init.vue";
		divm = menu_cont_Random+"_div999";
		random_subhtml = menu_cont_Random+"_";
		call_vue_funcName = "";
		$("#"+menu_cont_Random+"_div999").attr("data-id","init.vue");
		loadScript_nofun("init.vue?callback=ReadCommonRes");
	}
}

//设置菜单及相关信息,旧权限模式，已被废弃
//function get_APP_USER_ZXY(input){
//	layer.close(ly_index);
//	//查询失败
//	if (Call_QryResult(input.APP_USER_ZXY) == false)
//		return false;
//	var auz = input.APP_USER_ZXY;
//	var menu_info = input.T01_JK7788;
//	var menu_group = input.T01_JKTFSA;
//	var menu_content = input.T01_JK3344;
//	var menu_ccode = input.T01_KT33V5;
//	$.each(menu_group, function (i, obj) {
//		var temROLE_ID = s_decode(obj[GetLowUpp("ROLE_ID")]).split(",");//: "1%2C2%2C3%2C4
//		var btFlag = false;
//		for(var n = 0; n < temROLE_ID.length; n ++){
//			if(temROLE_ID[n].toString() == role_id.toString()){
//				btFlag = true;
//				break;
//			}
//		}
//		if(btFlag){
//			var divGroup = "<li class=\"active\" id=\""+obj[GetLowUpp("GROUP_EN_NAME")]+"\">"
//					 +"		<a href=\"#\">"
//					 +"			<i class=\""+s_decode(obj[GetLowUpp("GROUP_ICON")])+"\"></i>"
//					 +"			<span class=\"nav-label\">"+s_decode(obj[GetLowUpp("GROUP_CN_NAME")])+"</span>"
//					 +"			<span class=\"fa arrow\"></span>"
//					 +"		</a>"
//					 +"		<ul class=\"nav nav-second-level\" id =\""+obj[GetLowUpp("GROUP_EN_NAME")]+"_menu\">"
//					 +"		</ul>"
//					 +"</li>"
//			$("#side-menu").append(divGroup);
//			$.each(menu_info, function (j, objInfo) {
//				temROLE_ID = s_decode(objInfo[GetLowUpp("ROLE_ID")]).split(",");//: "1%2C2%2C3%2C4
//				btFlag = false;
//				for(var n = 0; n < temROLE_ID.length; n ++){
//					if(temROLE_ID[n].toString() == role_id.toString()){
//						btFlag = true;
//						break;
//					}
//				}
//				if(btFlag && obj[GetLowUpp("MAIN_ID")].toString() == objInfo[GetLowUpp("GROUP_ID")].toString()){
//					if(s_decode(objInfo[GetLowUpp("MENU_URL")]).lastIndexOf(".vue") != -1 && s_decode(objInfo[GetLowUpp("MENU_URL")]).lastIndexOf(".vue") == s_decode(objInfo[GetLowUpp("MENU_URL")]).length - 4)
//					{	var divMenuInfo = "<li>"
//										+ "<a class=\"J_menuItem\" href=\""+s_decode(objInfo[GetLowUpp("MENU_URL")])+"\" attRandom=\""+objInfo[GetLowUpp("S_DESC")]+"\">"+s_decode(objInfo[GetLowUpp("MENU_NAME")])+"</a>"
//										+ "</li>";
//						$("#"+obj[GetLowUpp("GROUP_EN_NAME")]+"_menu").append(divMenuInfo);
//					}
//					else
//					{
//						var divMenuInfo = "<li>"
//										+ "<a class=\"J_menuItem\" href=\""+s_decode(objInfo[GetLowUpp("MENU_URL")])+"\" attRandom=\""+objInfo[GetLowUpp("S_DESC")]+"\">"+s_decode(objInfo[GetLowUpp("MENU_NAME")])+"</a>"
//										+ "</li>";
//						$("#"+obj[GetLowUpp("GROUP_EN_NAME")]+"_menu").append(divMenuInfo);	
//					}
//				}
//			});
//		}
//	});
//	
//	var bFlag = false;
//	var menu_cont_Random = "T00000";
//	$.each(menu_ccode, function (j, objccfo){
//		$.each(menu_info, function (j, objInfo){
//			if(objccfo[GetLowUpp("MENU_ID")].toString() == objInfo[GetLowUpp("MAIN_ID")].toString()){
//				if(objccfo[GetLowUpp("S_DESC")] != "")
//					menu_cont_Random = objccfo[GetLowUpp("S_DESC")];
//			}
//		});
//	});
//	
//	$.each(menu_content, function (k, objCont) {
//		$.each(menu_info, function (j, objInfo) {
//			if(objInfo[GetLowUpp("MAIN_ID")].toString() == objCont[GetLowUpp("MENU_ID")].toString()){
//				var temUrl = s_decode(objInfo[GetLowUpp("MENU_URL")]);
//				var iR = IsVueOrHml(temUrl);
//				if(iR == 2){
//					$("#main_menu").attr("data-id",temUrl);
//					$("#iframe0").attr("src",temUrl);
//					$("#iframe0").attr("data-id",temUrl);
//					$("#iframe0").show();
//				}
//				else if(iR == 1){
//					$("#main_menu").attr("data-id",temUrl);
//					$("#main_menu").attr("attrandom",menu_cont_Random);
//					$("#iframe0").hide();
//					var nn = "<div id='"+menu_cont_Random+"_div999' name='"+menu_cont_Random+"_div999'></div>";
//					$(".J_mainContent").append(nn);
//					index_subhtml = temUrl;
//					divm = menu_cont_Random+"_div999";
//					random_subhtml = menu_cont_Random+"_";
//					call_vue_funcName = "";
//					$("#"+menu_cont_Random+"_div999").attr("data-id",temUrl);
//					loadScript_nofun(temUrl+"?callback=ReadCommonRes");
//				}
//				bFlag = true;
//			}
//		});
//	});
//	
//	if(bFlag == false)
//	{
//		$("#iframe0").hide();
//		$("#main_menu").attr("data-id","init.vue");
//		$("#main_menu").attr("attrandom",menu_cont_Random);
//		var nn = "<div id='"+menu_cont_Random+"_div999' name='"+menu_cont_Random+"_div999'></div>";
//		$(".J_mainContent").append(nn);
//		index_subhtml = "init.vue";
//		divm = menu_cont_Random+"_div999";
//		random_subhtml = menu_cont_Random+"_";
//		call_vue_funcName = "";
//		$("#"+menu_cont_Random+"_div999").attr("data-id","init.vue");
//		loadScript_nofun("init.vue?callback=ReadCommonRes");
//	}
//}

//vue回调
function index_call_vue(objResult){
	//更改密码
	if(index_subhtml == "upd_pwd.vue")
	{
		var divSub = "<div id='B44HT5_div' name='B44HT5_div' style='display:none'></div>";
		$("body").append(divSub)
		$("#B44HT5_div").append(objResult);		
		layer.open({
			type:1,
			area: ['600px', '350px'],
			fixed: false, //不固定
			maxmin: true,
			content: $("#B44HT5_div"),
			success: function(layero, index){
				B44HT5_ly_index = index;
				var data = {
					"ly_index":index
				};
	        	loadScript_hasparam("upd_pwd.js","B44HT5_start",data);
			},
			cancel: function(){
			}
		});
	}
	//其他事件触发
	else
	{
		//前端加载子页面div
		$("#"+divm).append(objResult);
		var index_suburl = index_subhtml.substring(0,index_subhtml.lastIndexOf(".vue"));
		var index_subname = index_suburl.substring(index_subhtml.lastIndexOf("/")+1,index_suburl.length);
		loadScript_hasparam(index_suburl+".js",random_subhtml+index_subname+"_biz_start",Temp_toparam);
		//全局变量传递页面参数重置
		Temp_toparam = {};
	}
}

//页面按钮权限设置
function page_btn_priv(temDivRan){
	var n = Get_RandomDiv(temDivRan,"");
	var buttons = $(n).find('button');
	$.each(T00000_N01_GHT003, function (i, objAry) {
		$.each(buttons, function (i, objSub) {
			if(objSub.id != "" && objSub.id == objAry.BTN_EN_NAME){
				$(objSub).hide();
			}
		});
	});
}

$(document).ready(function () {
	init_page();
});